package com.adaxi.adc.business.passengertrip.controller;

import com.adaxi.adc.business.passengertrip.feign.service.IVehicleTripFeignService;
import com.adaxi.adc.business.passengertrip.pojo.AdcPassengerTrip;
import com.adaxi.adc.business.passengertrip.pojo.AdcVehicleTrip;
import com.adaxi.adc.business.passengertrip.service.IPersonalTripService;
import com.adaxi.adc.common.common.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(value = "个人行程查询接口")
@RestController
public class PersonalTripController {
    @Autowired
    RocketMQTemplate rocketMQTemplate;

    @Autowired
    IPersonalTripService iPersonalTripService;

    @Autowired
    IVehicleTripFeignService iVehicleTripFeignService;

    @ApiOperation("乘客行程查询")
    @GetMapping("/mytrip/check")
    public CommonResult queryAllById(@RequestParam Long passengerId) {
        List<AdcPassengerTrip> adcPassengerTrip = iPersonalTripService.getByPassengerId(passengerId);
        List<AdcPassengerTrip> adcPassengerTrips_VehicleTrip = new ArrayList<>();
        for (AdcPassengerTrip element : adcPassengerTrip) {
            String vehicleTripId = element.getVehicleTripId();
            CommonResult<AdcVehicleTrip> result = iVehicleTripFeignService.queryById(vehicleTripId);
            if (result.isSuccess()) {
                AdcVehicleTrip vehicleTrip = result.getData();
                element.setAdcVehicleTrip(vehicleTrip);
            }
            adcPassengerTrips_VehicleTrip.add(element);
        }
        if (adcPassengerTrips_VehicleTrip != null)
            return CommonResult.SUCCESS("查询个人行程成功！", adcPassengerTrips_VehicleTrip);
        else
            return CommonResult.FAILURE("查询失败！");
    }
}
